home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!xmission!news
- From: macron@xmission.com (Joe Schlimgen)
- Newsgroups: comp.lang.c++
- Subject: Re: How to print a enum variable's names
- Date: Fri, 05 Jan 1996 22:36:19 GMT
- Organization: XMission Internet (801 539 0900)
- Message-ID: <30eda78e.3109304@news.xmission.com>
- References: <4cjohq$k5u@lsi.lsil.com>
- NNTP-Posting-Host: slc12.xmission.com
- X-Newsreader: Forte Agent .99c/16.141
-
- On 5 Jan 1996 17:52:58 GMT, song@lsil.com (Song Liang) wrote:
-
- > Suppose you have a variable foo of type "enum bar_type {CAR TRUCK VAN}", if
- >you do "cout << foo", it will print either 0, 1 or 2. Is there a simple trick
- >to print the names, i.e CAR, TRUCK or VAN?
-
- enum bar_type { CAR, TRUCK, VAN };
- const char bar_type_string { "Car", "Truck", "Van" };
-
- bar_type foo;
-
- cout << bar_type_string[foo];
-
-